<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn">点击按钮</button>
    <script>
      const btn = document.querySelector('#btn')

      // 会覆盖前面的 onclick
      btn.onclick = function () {
        console.log('1')
      }
      btn.onclick = function () {
        console.log('2')
      }
      btn.onclick = function () {
        console.log('3')
      }

      // 不覆盖前面添加的 click 事件，全部叠加运行
      btn.addEventListener('click', () => {
        console.log(1)
      })
      btn.addEventListener('click', () => {
        console.log(2)
      })
      btn.addEventListener('click', () => {
        console.log(3)
      })
    </script>
  </body>
</html>
